<!DOCTYPE html>
<html lang="en" xmlns:th="https://www.thymeleaf.org/">
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/public/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/public/css/public.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">全宗名称</label>
        <div class="layui-input-block">
            <input type="text" name="fondsName" lay-verify="required" lay-reqtext="全宗名称不能为空" placeholder="请输入全宗名称" value="" class="layui-input">
            <tip>填写全宗名称</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">全宗号</label>
        <div class="layui-input-block">
            <input type="text" name="fondsCode"  placeholder="请输入全宗号"  class="layui-input"/>
            <tip>填写全宗号</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label ">父全宗</label>
        <div class="layui-input-block">
            <input type="text" id="pidSelect" name="parentCode" value="-1" lay-filter="pidSelect" placeholder="选择父节点" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea name="fondsDesc" class="layui-textarea" placeholder="请输入描述信息"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script th:src="@{/public/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        let form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.post("/system/fonds/add", data.field, function (res) {
                if (res.code === 200) {
                    layer.msg("添加全宗成功!", {icon: 1, time: 1000}, function () {
                        let iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });
                } else {
                    layer.msg(res.msg, {icon: 2, time: 1000});
                }
            });

            return false;
        });

    });
</script>
<script>
    layui.config({
        base: '/public/js/lay-module/'
    }).extend({
        treeSelect: 'tree/treeSelect'
    });
    layui.use(['treeSelect','jquery'], function () {
        var treeSelect= layui.treeSelect;
        let $ = layui.jquery;
        // 初始化下拉选择器
        treeSelect.render({
            // css选择器，推荐使用id
            elem: '#pidSelect',
            // 请求地址
            data: '/system/fonds/fonds_tree',
            // ajax请求方式：post/get
            type: 'get',
            // 返回数据中主键的属性名称，默认值为id
            key: {
                id: 'fondsCode',
            },
            // 节点点击回调函数
            click: function (d) {
                console.log(d);
                $("input[name='parentCode']").val(d.current.fondsCode);
            }
            // ,success: function () {
            //     console.log("加载完成")
            //     /*
            //      *  选中节点（常用于更新时默认选中节点）
            //      *  第一个参数为lay-filter属性的值
            //      *  第二个参数为需要选中的节点的id
            //      */
            //     treeSelect.checkNode('pidSelect', 5);
            // }
        });

        /*
         *  手动设置占位符placeholder（不常用）
         *  第一个参数为lay-filter属性的值
         *  第二个参数为需要修改的提示内容
         */
        // treeSelect.setTitle('pidSelect', '这里填写要改的内容');


    });
</script>
</body>
</html>